//Jen Anderson
//CS 362
//Assignment 3
//unittest3.c

/*----------------------------------------------------------------------
  Unit test for isGameOver()
  Code borrowed heavily from testUpdateCoins() example given on 
  	blackboard
  Tests whether isGameOver()
	Test 1: returns 1 if there are no province cards left
	Test 2: returns 1 if there are 3 empty supply piles 	
----------------------------------------------------------------------*/

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <stdlib.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

void testIsGameOver() 
{
	//Initialize a test game and a compare game
        int k[10] = {adventurer, council_room, feast, gardens, mine,remodel, smithy, village, baron, great_hall};
        struct gameState *game = newGame();
        initializeGame(3, k, 10, game);
        struct gameState *testGameState = malloc(sizeof(struct gameState));
        memcpy(testGameState, game, sizeof(struct gameState));
	
	/**********
 	* Test 1 
 	**********/
	//Check's the function's ability to check if Province cards are out
	testGameState->supplyCount[province] = 0;
	assert(isGameOver(testGameState) == 1);
	#if (NOISY_TEST == 1)
		printf("isGameOver() successfully detected there are no Province cards left.\n");
	#endif
   
	/********
  	* Test 2
  	********/	
	//Reset the number of province cards in the test case
	//Set three supplies to 0 and check if the function returns 0
	testGameState->supplyCount[province] = 2;
	testGameState->supplyCount[duchy] = 0;
	testGameState->supplyCount[smithy] = 0;
	testGameState->supplyCount[curse] = 0;
	assert(isGameOver(testGameState) == 1);
	#if (NOISY_TEST == 1)
		printf("isGameOver() successfully detected there are three supply piles at 0.\n");
	#endif
}

int main()
{
	testIsGameOver();
	return 0;
}
